<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>【按键事件】</title>
    <style rel="stylesheet" type="text/css">
        *{
            margin: 0;
            padding: 0;
        }
    </style>
    <script type="text/javascript">
        window.addEventListener("load", function () {
            document.addEventListener("keydown", function (event) {
                console.log(event.key);
            });
            document.addEventListener("keyup", function (event) {
                console.log(event.key);
            });
            document.onkeypress = function (event) {
                console.log(event.keyCode);
            };
        });
    </script>
</head>
<body>

</body>
</html>